package com.demo.web.generator.tool.impl;

import com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.demo.web.dao.${domainObjectName}Dao;
import com.demo.web.generator.entity.${domainObjectName};
import com.demo.web.generator.params.${lowerDomainObjectName}.req.ReqDelete;
import com.demo.web.generator.params.${lowerDomainObjectName}.req.ReqSelectOne;
import com.demo.web.generator.params.${lowerDomainObjectName}.req.ReqSelectPage;
import com.demo.web.generator.params.${lowerDomainObjectName}.req.ReqUpdate;
import com.demo.web.generator.tool.${domainObjectName}Tool;
import org.springframework.stereotype.Service;

/**
 * @author fengz
 * @version v1
 * @className ${domainObjectName}ToolImpl
 * @description TODO
 * @site glp.hcdlearning.com
 * @company 合得软件（上海）有限公司
 * @create ${date} ${time}
 */
@Service
public class ${domainObjectName}ToolImpl implements ${domainObjectName}Tool {

    ${domainObjectName}Dao ${lowerDomainObjectName}Dao;

    @Override
    public IPage<${domainObjectName}> selectPage(ReqSelectPage reqSelectPage) {
        AbstractLambdaWrapper<${domainObjectName},?> wrapper = reqSelectPage.getCriterion().buildQuery();
        if(reqSelectPage.getBuildWrapper() != null){
            wrapper = reqSelectPage.getBuildWrapper().build(wrapper);
        }
        return ${lowerDomainObjectName}Dao.selectPage(reqSelectPage.toMybatisPlusPage(),wrapper);
    }

    @Override
    public ${domainObjectName} selectOne(ReqSelectOne reqSelectOne) {
        AbstractLambdaWrapper<${domainObjectName},?> wrapper = reqSelectOne.getCriterion().buildQuery();
        if(reqSelectOne.getBuildWrapper() != null){
            wrapper = reqSelectOne.getBuildWrapper().build(wrapper);
        }
        return ${lowerDomainObjectName}Dao.selectOne(wrapper);
    }

    @Override
    public int update(ReqUpdate reqUpdate) {
        AbstractLambdaWrapper<${domainObjectName},?> wrapper = reqUpdate.getCriterion().buildUpdate();
        if(reqUpdate.getBuildWrapper() != null){
            wrapper = reqUpdate.getBuildWrapper().build(wrapper);
        }
        return ${lowerDomainObjectName}Dao.update(reqUpdate.getUpdateSetField(),wrapper);
    }

    @Override
    public int delete(ReqDelete reqDelete) {
        AbstractLambdaWrapper<${domainObjectName},?> wrapper = reqDelete.getCriterion().buildUpdate();
        if(reqDelete.getBuildWrapper() != null){
            wrapper = reqDelete.getBuildWrapper().build(wrapper);
        }
        return ${lowerDomainObjectName}Dao.delete(wrapper);
    }

}
